<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <base data-ice="baseUrl" href="../../../">
  <title data-ice="title">src/contextMenus/SectionToolContextMenu.js | xeokit-bim-viewer</title>
  <link type="text/css" rel="stylesheet" href="css/style.css">
  <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
  <script src="script/prettify/prettify.js"></script>
  <script src="script/manual.js"></script>
<meta name="description" content="BIM viewer built on xeokit"><meta property="og:type" content="website"><meta property="og:url" content="https://github.com/xeokit/xeokit-bim-viewer"><meta property="og:site_name" content="xeokit-bim-viewer"><meta property="og:title" content="xeokit-bim-viewer"><meta property="og:image" content="./images/logo.jpg"><meta property="og:description" content="BIM viewer built on xeokit"><meta property="og:author" content="http://xeolabs.com"><meta property="twitter:card" content="summary"><meta property="twitter:title" content="xeokit-bim-viewer"><meta property="twitter:description" content="BIM viewer built on xeokit"><meta property="twitter:image" content="./images/logo.jpg"></head>
<body class="layout-container" data-ice="rootContainer">

<header>
  <a href="./" style="display: flex; align-items: center;"><img src="./image/brand_logo.jpg" style="width:34px;"></a>
  
  <a href="identifiers.html">Reference</a>
  <a href="source.html">Source</a>
  
  <div class="search-box">
  <span>
    <img src="./image/search.png">
    <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
  </span>
    <ul class="search-result"></ul>
  </div>
<a style="position:relative; top:3px;" href="https://github.com/xeokit/xeokit-bim-viewer"><img width="20px" src="./image/github.png"></a></header>

<nav class="navigation" data-ice="nav"><div>
  <ul>
    
  <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/BIMViewer.js~BIMViewer.html">BIMViewer</a></span></span></li>
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#collision">collision</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/collision/ObjectsKdTree3.js~ObjectsKdTree3.html">ObjectsKdTree3</a></span></span></li>
<li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#server">server</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/server/Server.js~Server.html">Server</a></span></span></li>
</ul>
</div>
</nav>

<div class="content" data-ice="content"><h1 data-ice="title">src/contextMenus/SectionToolContextMenu.js</h1>
<pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import {ContextMenu, math, utils} from &quot;@xeokit/xeokit-sdk/dist/xeokit-sdk.es.js&quot;;

const tempAABB = math.AABB3();
const tempVec3 = math.vec3();

/**
 * @private
 */
class SectionToolContextMenu extends ContextMenu {

    constructor(cfg = {}) {

        if (!cfg.sectionPlanesPlugin) {
            throw &quot;Missing config: sectionPlanesPlugin&quot;;
        }

        super(utils.apply({}, cfg));

        this._sectionPlanesPlugin = cfg.sectionPlanesPlugin;
        this._viewer = this._sectionPlanesPlugin.viewer;

        this._onSceneSectionPlaneCreated = this._viewer.scene.on(&quot;sectionPlaneCreated&quot;, () =&gt; {
            this._buildMenu();
        });

        this._onSceneSectionPlaneDestroyed = this._viewer.scene.on(&quot;sectionPlaneDestroyed&quot;, () =&gt; {
            this._buildMenu();
        });

        this._buildMenu();
    }

    _buildMenu() {

        const sectionPlanesPlugin = this._sectionPlanesPlugin;
        const sectionPlanes = Object.values(sectionPlanesPlugin.sectionPlanes);

        const sectionPlanesMenuItems = [];

        for (let i = 0, len = sectionPlanes.length; i &lt; len; i++) {

            const sectionPlane = sectionPlanes[i];

            sectionPlanesMenuItems.push({

                getTitle: (context) =&gt; {
                    return `${context.viewer.localeService.translate(&quot;sectionToolContextMenu.slice&quot;) || &quot;Slice&quot;} #` + (i + 1);
                },

                doHoverEnter(context) {
                    sectionPlanesPlugin.hideControl();
                    sectionPlanesPlugin.showControl(sectionPlane.id);
                },

                doHoverLeave(context) {
                    sectionPlanesPlugin.hideControl();
                },

                items: [ // Submenu
                    [ // Group
                        {
                            getTitle: (context) =&gt; {
                                return sectionPlane.active
                                    ? context.viewer.localeService.translate(&quot;sectionToolContextMenu.deactivate&quot;) || &quot;Disable&quot;
                                    : context.viewer.localeService.translate(&quot;sectionToolContextMenu.activate&quot;) || &quot;Enable&quot;;
                            },
                            doAction: (context) =&gt; {
                                sectionPlane.active = !sectionPlane.active;
                            }
                        },
                        {
                            getTitle: (context) =&gt; {
                                return context.viewer.localeService.translate(&quot;sectionToolContextMenu.edit&quot;) || &quot;Edit&quot;;
                            },
                            getEnabled() {
                              return sectionPlane.active;
                            },
                            doAction: (context) =&gt; {

                                sectionPlanesPlugin.hideControl();
                                sectionPlanesPlugin.showControl(sectionPlane.id);

                                const sectionPlanePos = sectionPlane.pos;
                                tempAABB.set(this._viewer.scene.aabb);
                                math.getAABB3Center(tempAABB, tempVec3);
                                tempAABB[0] += sectionPlanePos[0] - tempVec3[0];
                                tempAABB[1] += sectionPlanePos[1] - tempVec3[1];
                                tempAABB[2] += sectionPlanePos[2] - tempVec3[2];
                                tempAABB[3] += sectionPlanePos[0] - tempVec3[0];
                                tempAABB[4] += sectionPlanePos[1] - tempVec3[1];
                                tempAABB[5] += sectionPlanePos[2] - tempVec3[2];

                                this._viewer.cameraFlight.flyTo({
                                    aabb: tempAABB,
                                    fitFOV: 65
                                });
                            }
                        },
                        {
                            getTitle: (context) =&gt; {
                                return context.viewer.localeService.translate(&quot;sectionToolContextMenu.flip&quot;) || &quot;Flip&quot;;
                            },
                            getEnabled() {
                                return sectionPlane.active;
                            },
                            doAction: (context) =&gt; {
                                sectionPlane.flipDir();
                            }
                        },

                        {
                            getTitle: (context) =&gt; {
                                return context.viewer.localeService.translate(&quot;sectionToolContextMenu.delete&quot;) || &quot;Delete&quot;;
                            },
                            doAction: (context) =&gt; {
                                sectionPlane.destroy();
                            }
                        }
                    ]
                ]
            });
        }

        this.items = [
            [
                {
                    getTitle: (context) =&gt; {
                        return context.viewer.localeService.translate(&quot;sectionToolContextMenu.clearSlices&quot;) || &quot;Clear Slices&quot;;
                    },
                    getEnabled: (context) =&gt; {
                        return (context.bimViewer.getNumSections() &gt; 0);
                    },
                    doAction: (context) =&gt; {
                        context.bimViewer.clearSections();
                    }
                },
                {
                    getTitle: (context) =&gt; {
                        return context.viewer.localeService.translate(&quot;sectionToolContextMenu.flipSlices&quot;) || &quot;Flip Slices&quot;;
                    },
                    getEnabled: (context) =&gt; {
                        return (context.bimViewer.getNumSections() &gt; 0);
                    },
                    doAction: (context) =&gt; {
                        context.bimViewer.flipSections();
                    }
                }
            ],

            [
                {
                    getTitle: (context) =&gt; {
                        return context.viewer.localeService.translate(&quot;sectionToolContextMenu.disableAllSlices&quot;) || &quot;Disable all Slices&quot;;
                    },
                    getEnabled: (context) =&gt; {
                        return (context.bimViewer.getNumSections() &gt; 0);
                    },
                    doAction: (context) =&gt; {
                        context.bimViewer.disableSections();
                    }
                },
                {
                    getTitle: (context) =&gt; {
                        return context.viewer.localeService.translate(&quot;sectionToolContextMenu.enableAllSlices&quot;) || &quot;Enable all Slices&quot;;
                    },
                    getEnabled: (context) =&gt; {
                        return (context.bimViewer.getNumSections() &gt; 0);
                    },
                    doAction: (context) =&gt; {
                        context.bimViewer.enableSections();
                    }
                }
            ],
            sectionPlanesMenuItems
        ];
    }

    destroy() {
        super.destroy();
        const scene = this._viewer.scene;
        scene.off(this._onSceneSectionPlaneCreated);
        scene.off(this._onSceneSectionPlaneDestroyed);
    }
}


export {SectionToolContextMenu};</code></pre>

</div>

<footer class="footer">
  Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.1.0)</span><img src="./image/esdoc-logo-mini-black.png"></a>
</footer>

<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>
